package Splash;

import Splash.Constant;
import com.huajx.kit.Prop;
import com.huajx.kit.PropKit;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

@SuppressWarnings("restriction")
public class TcpServer extends Application {    
    @Override
    public void start(Stage stage) throws Exception {           
        FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
        Prop prop = PropKit.use("config.properties");
        
        String schoolName = prop.get(Constant.school_name);
        Parent root = loader.load();
        Scene scene = new Scene(root);        
        stage.setScene(scene);
        
         // 设置窗体标题
//        stage.setTitle(schoolName + "考勤数据采集平台");
        stage.setTitle("消息服务中间件");
        
        // 设置窗体图标
        stage.getIcons().add(new Image(getClass().getResourceAsStream("di.png")));
        
        // 设置到屏幕中心
        stage.centerOnScreen();      
        
        // 设置窗口关闭处理函数
        stage.setOnCloseRequest((WindowEvent e) -> {
            FXMLDocumentController controller = loader.getController();
            if(controller.mTcpServer != null)
            {
                controller.mTcpServer.dispose(true);
                controller.mTcpServer = null;
            }
        });
        
        // 显示窗体
        stage.show();       
    }
    
    public static void main(String[] args) {
        launch(args);
    }    
}
